package com.kzd.btgame.main.home.adapter

import android.widget.ImageView
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.kzd.btgame.R
import com.kzd.btgame.entity.BargainRecord
import com.kzd.btgame.entity.GameBargain
import com.kzd.btgame.main.toBargainDetailsActivity
import com.module.lemlin.image.loadImage
import com.module.lemlin.image.loadRoundImage


class BargainFeaturedAdapter :
    BaseQuickAdapter<GameBargain, BaseViewHolder>(R.layout.item_game_bargain_featured) {

    init {
        setOnItemClickListener { _, _, position ->
            val itemData = getItem(position)
            toBargainDetailsActivity(itemData.id)
        }
    }

    override fun convert(holder: BaseViewHolder, item: GameBargain) {
        holder.setText(R.id.tvGameBargainFeaturedName, item.gameName)
            .setText(R.id.tvGameBargainFeaturedType, item.name)
            .setText(R.id.tvGameBargainFeaturedPrice, "￥${item.money}")
            .getView<ImageView>(R.id.ivGameBargainFeaturedIcon)
            .loadImage(item.icon)
    }
}

class BargainReleaseAdapter :
    BaseQuickAdapter<GameBargain, BaseViewHolder>(R.layout.item_game_bargain_release) {

    init {
        setOnItemClickListener { _, _, position ->
            val itemData = getItem(position)
            toBargainDetailsActivity(itemData.id)
        }
    }

    override fun convert(holder: BaseViewHolder, item: GameBargain) {
        holder.setText(R.id.tvBargainReleaseName, item.gameName)
            .setText(R.id.tvBargainReleaseDesc, item.name)
            .setText(R.id.tvBargainReleasePrice, "￥${item.money}")
            .getView<ImageView>(R.id.ivBargainReleaseImage)
            .loadImage(item.images)
    }
}


class BargainRecordAdapter :
    BaseQuickAdapter<BargainRecord, BaseViewHolder>(R.layout.item_game_bargain_record) {

    init {
        setOnItemClickListener { _, _, position ->
            val itemData = getItem(position)
            toBargainDetailsActivity(itemData.id)
        }
    }

    override fun convert(holder: BaseViewHolder, item: BargainRecord) {
        holder.setText(R.id.tvGameBargainName, item.gname)
            .setText(R.id.tvGameBargainDesc, item.name)
            .setText(R.id.tvGameBargainPrice, "￥${item.money}")
            .setText(
                R.id.tvGameBargainTime,
                StringBuilder().append("创建时间：").append(item.time)
            )
            .getView<ImageView>(R.id.ivGameBargainImage)
            .loadImage(item.image)

        holder.getView<ImageView>(R.id.ivGameBargainStatus).apply {
            if (item.status == "0" && item.shop_ok == "0") {
                setImageResource(R.mipmap.trade_checking_icon)
            } else if (item.status == "1" && item.shop_ok == "0") {
                setImageResource(R.mipmap.trade_checked_icon)
            } else if (item.status == "1" && item.shop_ok == "1") {
                setImageResource(R.mipmap.trade_finish_icon)
            } else if (item.status == "2") {
                setImageResource(R.mipmap.trade_rejected_icon)
            } else {
                setImageResource(0)
            }
        }

        //待审核status=0，shop_ok=0
        //出售中status=1，shop_ok=0
        //已出售status=1，shop_ok=1
        //已购买status=1，shop_ok=1，buy_uid
        //审核未通过status=2,shop_ok=0
    }
}

class ImageSelectAdapter :
    BaseQuickAdapter<Any, BaseViewHolder>(R.layout.item_image_select) {
    override fun convert(holder: BaseViewHolder, item: Any) {
        holder.getView<ImageView>(R.id.ivImageSelectIcon)
            .loadRoundImage(item, radius = ConvertUtils.dp2px(5f))
    }
}

class BargainImageAdapter :
    BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_game_bargain_image) {
    override fun convert(holder: BaseViewHolder, item: String) {
        holder.getView<ImageView>(R.id.tvGameBargainDetailsImageIcon)
            .loadRoundImage(item, radius = ConvertUtils.dp2px(5f))
    }
}

